#include    "pausedscene.h"

#include    "../ui/input/mouseinputmanager.h"
#include    "../audio/audio_engine.h"


PausedScene::PausedScene(GameApp* app,Scene* running):
AppScene(app),
m_running(running)
{
    m_menuButton = new Button("resources/menuButton.png",75,38);
    m_menuButton->m_function = [this](int a,int b){ this->menuClicked(); };
    m_menuButton->setPosition(385,270);

    m_resumeButton = new Button("resources/resumeButton.png",75,38);
    m_resumeButton->m_function = [this](int a,int b){ this->resumeClicked(); };
    m_resumeButton->setPosition(385,320);

    on();
}

PausedScene::~PausedScene()
{
    SAFE_DELETE_OBJ(m_menuButton);
    SAFE_DELETE_OBJ(m_resumeButton);
}

void PausedScene::render()
{
    m_running->render();
    m_menuButton->render();
    m_resumeButton->render();
}

void PausedScene::menuClicked()
{
    std::string button = "button";
    AudioEngine::getInstance()->playSound(button);

    off();
    m_app->setGameState(GameApp::GAMESTATE_MENU);
}

void PausedScene::resumeClicked()
{
    std::string button = "button";
    AudioEngine::getInstance()->playSound(button);

    off();
    m_app->setGameState(GameApp::GAMESTATE_RUNNING);
}


void PausedScene::on()
{
    if(switchOpen == true){return;}

    MouseInputManager* mouseInputManager = MouseInputManager::getInstance();
    mouseInputManager->addClickable(m_menuButton);
    mouseInputManager->addClickable(m_resumeButton);

    Switch::on();
}

void PausedScene::off()
{
    MouseInputManager::getInstance()->removeAllClickable();
    Switch::off();
}

